package com.gis507.test.AISTest;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 1、继承Mapper类
 * 2、确定输入和输出类型
 * 3、重写map方法
 */
public class AisMapper extends Mapper<LongWritable, Text, AisBean, LongWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1、转为字符串
        String line = value.toString();

        //2、切割按照，
        String[] comment = line.split(",");

        //3、取出需要的值
        Long mmsi = Long.parseLong(comment[0]);
        String speed = comment[1];
        Long unixTime = Long.parseLong(comment[2]);
        Double Lon_d = Double.parseDouble(comment[3]);
        Double Lat_d = Double.parseDouble(comment[4]);

        //4、封装到对象中
        AisBean ais = new AisBean();

        ais.setMmsi(mmsi);
        ais.setSpeed(speed);
        ais.setUnixTime(unixTime);
        ais.setLon_d(Lon_d);
        ais.setLat_d(Lat_d);

        //5、封装输出V，用mmsi
        LongWritable outV = new LongWritable();
        outV.set(mmsi);

        //6、写出
        context.write(ais,outV);
    }
}
